package com.atu.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HelloServlet2 extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);//在继承的HttpServlet类中，重写init()方法，必须调用这个方法，并把形参值放加进去
        System.out.println("重写了初始化方法22222");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("get请求");
//        2、获取初始化参数 init-param
        ServletConfig servletConfig = getServletConfig();
        System.out.println(servletConfig);
        System.out.println("用户名："+servletConfig.getInitParameter("username"));
        System.out.println("用户密码："+servletConfig.getInitParameter("password"));
        System.out.println(servletConfig.getServletContext());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("post请求");

    }
}
